'https://www.doyo.cn/passport/login?next=https://www.doyo.cn'
import requests
import json
import hashlib

cookies = {
    'acw_tc': 'b659c00517243816408215045e77c9d039ac9c53559f0934360d46af21',
    'cdn_sec_tc': 'b659c00517243816408215045e77c9d039ac9c53559f0934360d46af21',
    'PHPSESSID': 'b5gsbuj90sei7rn2phs79j3al4',
    'doyo_www_uv_mark': 'true',
    'Hm_lvt_b0affa74a0ef00f793803b2ae8a25f8a': '1724381643',
    'HMACCOUNT': 'D9D3E07B7FE17F0D',
    'Hm_lpvt_b0affa74a0ef00f793803b2ae8a25f8a': '1724381704',
}

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    # 'Cookie': 'acw_tc=b659c00517243816408215045e77c9d039ac9c53559f0934360d46af21; cdn_sec_tc=b659c00517243816408215045e77c9d039ac9c53559f0934360d46af21; PHPSESSID=b5gsbuj90sei7rn2phs79j3al4; doyo_www_uv_mark=true; Hm_lvt_b0affa74a0ef00f793803b2ae8a25f8a=1724381643; HMACCOUNT=D9D3E07B7FE17F0D; Hm_lpvt_b0affa74a0ef00f793803b2ae8a25f8a=1724381704',
    'Pragma': 'no-cache',
    'Referer': 'https://www.doyo.cn/passport/login?next=https://www.doyo.cn',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'username': 'a123456',
    'random': '0.5512856762212468',
}

response = requests.get('https://www.doyo.cn/User/Passport/token', params=params, cookies=cookies, headers=headers)
# pwd = Sha1.hash($(".login_grey[name='user_password']").val());
# pwd = Sha1.hash(nonce + ts + pwd);
print(response.text.strip())
# 创建 SHA-1 哈希对象
user_password = hashlib.sha1()
# 更新哈希对象，传入字节数据
user_password.update('123456'.encode('utf-8'))
# 获取最终的哈希值
user_password_value = user_password.hexdigest()
nonce = json.loads(response.text.strip())['nonce']
ts = json.loads(response.text.strip())['ts']
print(nonce, ts)
pwd = hashlib.sha1()
pwd.update((user_password_value + nonce + str(ts)).encode('utf-8'))
pwd_value = pwd.hexdigest()
print(pwd_value)

data_ = {
    'username': 'a123456',
    'password': pwd_value,
    'remberme': '1',
    'next': 'aHR0cHMlM0ElMkYlMkZ3d3cuZG95by5jbg==',
}

response = requests.post('https://www.doyo.cn/User/Passport/login', cookies=cookies, headers=headers, data=data_)
print(response.text)